package com.intel.two.listener.smarthome;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.intel.two.bo.building.ResidentBo;
import com.intel.two.bo.smarthome.HouseholdBo;
import com.intel.two.pojo.building.Resident;
import com.intel.two.pojo.smarthome.Household;
import com.intel.two.service.smarthome.HouseholdService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * @BelongsProject: intelligentcommunity
 * @BelongsPackage: com.intel.two.listener.smarthome
 * @Author: yanhongwei
 * @CreateTime: 2022-10-15  23:52
 * @Description: TODO
 * @Version: 1.0
 */
@Component
@Scope("prototype")//多例模式
public class WebHouseholdListener extends AnalysisEventListener<HouseholdBo> {
    @Autowired
    private HouseholdService householdService;
    //导入表格
    @Override
    public void invoke(HouseholdBo data, AnalysisContext context) {
        System.out.println(data);//这里的data不一致，只是获得属性值

        Household household = new Household();

        //将data属性的值拷贝给和数据库交互的的实体类household
        BeanUtils.copyProperties(data,household);

        //每复制一行数据，就添加一次
        householdService.householdAdd(household);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {

    }
}
